package com.jnevision.sysconfig.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.jnevision.attendancegroup.model.AttendanceGroup;
import com.jnevision.attendancegroup.service.AttendanceGroupServiceImpl;
import com.jnevision.config.Baidubce;
import com.jnevision.sysconfig.model.Config;
import com.jnevision.sysconfig.service.ConfigServiceImpl;
import com.jnevision.userdept.model.UserDept;
import com.jnevision.userdept.service.UserDeptServiceImpl;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gavin
 * @since 2019-07-14
 */

@RestController
@RequestMapping("/sysconfigs")
public class ConfigController extends ApiController {
    @Autowired
    private ConfigServiceImpl configServiceImpl;
    @Autowired
    private Baidubce baidubce;
    @Autowired
    private AttendanceGroupServiceImpl attendanceGroupServiceImpl;
    @Autowired
    private UserDeptServiceImpl userDeptServiceImpl;

    /**
     * 获取所有的系统配置
     * 
     * @return
     */
    @GetMapping("/all")
    public R<List<Config>> getAll() {
        return this.success(this.configServiceImpl.list());
    }

    /**
     * 关于我们
     * 
     * @return
     */
    @GetMapping("/aboutus")
    public R<Config> aboutus() {
        return this.success(this.configServiceImpl.getOne(new QueryWrapper<Config>().eq("name", "about_us")));
    }

    /**
     * 补卡次数
     * 
     * @return
     */
    @GetMapping("/patchCard")
    public R<String> patchCard(String userId) {
        UserDept ud = this.userDeptServiceImpl.getOne(new QueryWrapper<UserDept>().eq("user_id", userId));
        return this.success(this.attendanceGroupServiceImpl
            .getOne(new QueryWrapper<AttendanceGroup>().eq("dept_id", ud.getDeptId())).getReplaceCardNum());
        // return this.success(this.configServiceImpl.getOne(new QueryWrapper<Config>().eq("name", "patch_card")));
    }

    /**
     * 百度人脸识别的配置
     * 
     * @return
     */
    @GetMapping("/baidubce")
    public R<Baidubce> baidubce() {
        return this.success(this.baidubce);
    }
}
